# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=regal
pkgver=0.21.3
pkgrel=0
pkgdesc="Linter for Rego files"
url="https://docs.styra.com/regal"
# riscv64: TestLanguageServerMultipleFiles test times out
arch="all !riscv64"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/StyraInc/regal/archive/refs/tags/v$pkgver.tar.gz"
options="net" # download Go modules

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local _goldflags="
	-X github.com/styrainc/regal/pkg/version.Version=v$pkgver
	-X github.com/styrainc/regal/pkg/version.Commit=AlpineLinux
	-X github.com/styrainc/regal/pkg/version.Timestamp=$(date -u "+%Y-%m-%dT%H:%M:%S%z" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	-X github.com/styrainc/regal/pkg/version.Hostname=alpinelinux.org
	"

	go build -v -ldflags "$_goldflags" .

	for shell in bash fish zsh; do
		./regal completion $shell > regal.$shell
	done
}

check() {
	go test ./...
}

package() {
	install -Dm755 regal -t "$pkgdir"/usr/bin/

	install -Dm644 regal.bash \
		"$pkgdir"/usr/share/bash-completion/completions/regal
	install -Dm644 regal.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/regal.fish
	install -Dm644 regal.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_regal
}

sha512sums="
766a723060074c26d19402e0e1ee17f25619a22d9eec50444a1eeaa02308c3e6dee4657e665c0e0122641f54c4cea422e9153ec0d741ef974f82320cd714be04  regal-0.21.3.tar.gz
"
